-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH/TST: Allow more keywords to ensure_clean #30915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
These keywords will be passed through to tempfile constructor functions. Follow-up: pandas-dev#30771
@@ -485,23 +485,37 @@ def ensure_clean(filename=None, return_filelike=False): | |||
return_filelike : bool (default False) | |||
if True, returns a file-like which is *always* cleaned. Necessary for | |||
savefig and other functions which want to append extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don’t list encoding , mode here explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and in the signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryFile
https://docs.python.org/3/library/tempfile.html#tempfile.mkstemp
encoding
and mode
are not accepted in mkstemp
.
The only shared parameters are prefix
, suffix
(corresponds to filename
in our signature), and dir
. Not sure that the remaining two need exposure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking back on comment in OP is the main thing needed for now just encoding? If so I think better to just list explicitly and not pass to mkstemp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so I think better to just list explicitly and not pass to mkstemp
The whole point is to use the **kwargs
in ensure_clean
as a pass through to mkstemp
or TemporaryFile
, depending on whether return_filelike
is true or false.
Explicitly listing arguments that apply to one but not the other is going to be confusing. What is being done is a lot more extensible in the long-run.
I would still vote for explicit arguments if anything but certainly open to input of others |
@pandas-dev/pandas-core : Thoughts? There seems to be some impasse regarding whether we should surface explicit arguments. I'm all for being explicit, but I also want them to make sense for both As we have it, |
this is fine as its only for testing, thanks @gfyoung however, I think it would be interesting to separate ensure_clean to 2 functions, e.g. ensure_clean_dir and ensure_clean_file; then you could have named keywords. not sure how much work that would be but might be a good followup . |
These keywords will be passed through to
tempfile
constructor functions.Follow-up:
#30771 (comment)